/**
 * Created by tdzl2003 on 7/22/16.
 */

export default function memoryCache(fetchData, options = {}) {
  const expires = options.expires || 60000;

  const cache = {};

  return id => {
    if (cache[id]) {
      return cache[id];
    }
    cache[id] = fetchData(id);
    cache[id].catch(() => {
      delete cache[id];
    });
    setTimeout(() => {
      delete cache[id];
    }, expires);
    return cache[id];
  };
}

